package com.unionpay.upyzt.example;


import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.model.BalanceFreeze;
import com.unionpay.upyzt.resp.BalanceFreezeResp;
import java.util.HashMap;
import java.util.Map;

public class BalanceFreezeExample {

    private String balanceAcctId;

    public BalanceFreezeExample(String balanceAcctId) {
        this.balanceAcctId = balanceAcctId;
    }

    public static void runDemos(String balanceAcctId) throws UpyztException {
        BalanceFreezeExample example = new BalanceFreezeExample(balanceAcctId);
        // 可提现余额冻结/解冻
        BalanceFreezeResp balanceFreezeResp = example.balanceFreeze();
        // 可提现余额冻结/解冻查询
        balanceFreezeResp = example.retrieveByOutOrderNo(balanceFreezeResp.getOutOrderNo());
    }

    /**
     * 可提现余额冻结/解冻
     *
     * @return 冻结/解冻结果
     */
    private BalanceFreezeResp balanceFreeze() throws UpyztException {
        Map<String, Object> params = new HashMap<>();
        params.put("out_order_no", Main.generateRandomOutNo());
        params.put("freeze_type", "1");
        params.put("settled_amount", 100);
        params.put("balance_acct_id", balanceAcctId);
        params.put("remark", "用于 SDK 示例测试");
        System.out.println("------- 可提现余额冻结/解冻 -------");
        BalanceFreezeResp resp = BalanceFreeze.balanceFreeze(params);
        System.out.println(resp);
        return resp;
    }

    /**
     * 可提现余额冻结/解冻查询
     *
     * @param outOrderNo 平台订单号
     * @return 冻结/解冻结果
     */
    private BalanceFreezeResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
        System.out.println("------- 可提现余额冻结/解冻查询 -------");
        BalanceFreezeResp resp = BalanceFreeze.retrieveByOutOrderNo(outOrderNo);
        System.out.println(resp);
        return resp;
    }
}
